package com.golddaymicromall.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.ShouYiLvInfo;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by dawd on 2016/3/3.
 */
public class DianZiLv_Adapter extends BaseAdapter {
    private List<ShouYiLvInfo> list;
    private Context ctx;

    public DianZiLv_Adapter(List<ShouYiLvInfo> list, Context ctx) {
        this.list = list;

        this.ctx = ctx;

    }


    @Override
    public int getCount() {
        return list.size();

    }

    @Override
    public Object getItem(int position) {
        return list.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder hold;
        if (convertView == null) {
            convertView = View.inflate(ctx, R.layout.item_dianzishouyilv, null);
            hold = new ViewHolder();
//            hold.mtype_shouru = (TextView) convertView.findViewById(R.id.type_shouru);
            hold.mjine_shouru = (TextView) convertView.findViewById(R.id.jine_shouru);
            hold.mtime_shouru = (TextView) convertView.findViewById(R.id.time_shouru);
            hold.mbeizhu = (TextView) convertView.findViewById(R.id.beizhu);

            convertView.setTag(hold);
        } else {
            hold = (ViewHolder) convertView.getTag();
        }
//        hold.mtype_shouru.setText(list.get(position).getName());
        if (list.get(position).getIncome() == 0) {
            hold.mjine_shouru.setText("-" + list.get(position).getInmoney());
        } else if (list.get(position).getIncome() == 1) {
            hold.mjine_shouru.setText("+" + list.get(position).getInmoney());
        }
        String ww=list.get(0).getBalance();
//        hold.myu_e.setText(list.get(position).getBalance());
        hold.mbeizhu.setText(list.get(position).getMemo());
        String getMessagedate=dateToString(list.get(position).getModifydate());
//        Log.e(">>>>>", getMessagedate);
        hold.mtime_shouru.setText(getMessagedate);
        return convertView;


    }

    public String dateToString(Date ctime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        return formatter.format(ctime);
    }

    private class ViewHolder {
        TextView mtype_shouru;
        TextView mjine_shouru;
        TextView myu_e;
        TextView mbeizhu;
        TextView mtime_shouru;
    }
}
